local unit_attribute = require 'types.unit_attribute'
local register = unit_attribute.register



--绿字属性处理
local attrs = {'攻击','护甲','魔抗','力量','敏捷','智力'}
for i,name in ipairs(attrs) do
    local base = ('基础%s'):format(name)
    local exsx = ('额外%s'):format(name)
    local rate = ('%s加成'):format(name)
    

    --总属性
    register(name,{
        on_get = function(self)
            return self:get(base) + self:get(exsx)
        end,
    })

    --基础
    register(base,{
        get = function(self)
            return 0
        end,
        set = function(self,value, old_value)
            if name=='力量' or name=='敏捷' or name=='智力' then
                self:notify('英雄-三维变动',self,name,value - old_value)
            end

            --额外变动
            self:add(exsx,0)
        end,
    })

    --额外
    register(exsx,{
        on_get = function(self,value)
            return self:get(base) * self:get(rate) / 100 + value
        end,
        set = function(self,value,old_value)
            if name=='力量' or name=='敏捷' or name=='智力' then
                self:notify('英雄-三维变动',self,name,value - old_value)
            end
        end
    })

    --加成
    register(rate,{
        set = function(self,value)
            self:add(exsx,0)
        end
    })
    
end



register('全属性加成',{
    on_set = function(self,change)
        self:add('力量加成',change)
        self:add('敏捷加成',change)
        self:add('智力加成',change)
    end,
})

register('每秒属性',{
    on_set = function(self,change)
        self:add('每秒力量',change)
        self:add('每秒敏捷',change)
        self:add('每秒智力',change)
    end,
})

local attrs = {
    {'生命上限','生命加成','生命增幅'},
    {'生命恢复','回血加成','回血增幅'},
}
for i,data in ipairs(attrs) do
    local base = data[1]
    local rate = data[2]
    local add2 = data[3]
    
    register(base,{
        on_get = function(self,value)
            return value * (1 + self:get(rate) / 100) * (1 + self:get(add2) / 100)
        end,
    })
    register(rate)
    register(add2)
    
end


register('分裂攻击')
register('分裂范围')
register('每秒金币')
register('每秒木材')
register('每秒杀敌')
register('选择套装')
register('完成套装')
register('自选套装',1)

register('多重射',1)


register('免费刷新',1)
register('复活时间',10)

register('力量成长',5)
register('敏捷成长',5)
register('智力成长',5)

register('主属性',{
    set = function(self,value,old_value)
        local old_class = self:get_data('修改前主属性')
        local now_class = ('基础%s'):format(self.main_attribute)
        if old_class then
            self:add(old_class,-old_value)
        end
        self:add(now_class,value)
        self:set_data('修改前主属性',now_class)
    end,
    on_get = function(self)
        return self:get(self.main_attribute)
    end
})


register('主属性成长',{
    set = function(self,value,old_value)
        local old_class = self:get_data('主属性成长类型')
        local now_class = ('%s成长'):format(self.main_attribute)
        if old_class then
            self:add(old_class,-old_value)
        end
        self:add(now_class,value)
        self:set_data('主属性成长类型',now_class)
    end,
})


register('冷却速度',100)

register('冷却缩减',{
    on_get = function(self)
        local a = math.max(math.min(self:get('冷却速度'),500),20) - 100
        return a/(1 + a*0.01)
    end
})

